package org.br.erp.base.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.br.erp.base.entity.IMperiod;
import org.br.erp.base.entity.Material;
import org.br.erp.base.entity.keyresult;
import org.br.erp.base.service.IKeyResultService;
import org.br.erp.base.service.IMaterialService;
import org.br.erp.base.vo.MaterialPage;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

@Api(tags="全局参数表")
@RestController
@RequestMapping("/base/keyresult")
@Slf4j
public class KeyResultController extends JeecgController<keyresult, IKeyResultService> {

    @Autowired
    private IKeyResultService keyResultService;

    @ApiOperation(value="参数表-分页列表查询", notes="参数表-分页列表查询")
    @GetMapping(value = {"/list"})
    public Result<IPage<keyresult>> queryPageList(keyresult keyresult,
                                                 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                 HttpServletRequest req) {
        QueryWrapper<keyresult> queryWrapper = QueryGenerator.initQueryWrapper(keyresult, req.getParameterMap());
        Page<keyresult> page=new Page<>(pageNo, pageSize);
        Page<org.br.erp.base.entity.keyresult> keyresultPage = keyResultService.page(page, queryWrapper);
        return Result.ok(keyresultPage);
    }

    @AutoLog(value = "参数表-添加")
    @ApiOperation(value="参数表-添加", notes="参数表-添加")
    //@RequiresPermissions("org.br.erp:material:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody keyresult keyresult) {
        keyResultService.save(keyresult);
        return Result.ok("添加成功");
    }

    @AutoLog(value = "参数表-编辑")
    @ApiOperation(value="参数表-编辑", notes="参数表-编辑")
    //@RequiresPermissions("org.br.erp:mvperiod:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<String> edit(@RequestBody keyresult keyresult) {
        keyResultService.updateById(keyresult);
        return Result.OK("编辑成功!");
    }


    @AutoLog(value = "参数表-通过id删除")
    @ApiOperation(value="参数表-通过id删除", notes="参数表-通过id删除")
    //@RequiresPermissions("org.br.erp:mvperiod:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name="id",required=true) String id) {
        keyResultService.removeById(id);
        return Result.OK("删除成功!");
    }



}
